#include <stdio.h>
#include <fcntl.h>      //O_RDWR
#include <unistd.h>     //open write read
#include <string.h>

static int value = 0;
int main(int argc, char** argv) {

    int fd;
    char buf[1024];
    int len;

    if (argc < 2)
    {
        printf("size < 2");
        return -1;
    }

    fd = open("/dev/hello", O_RDWR);

    if (fd == -1)
    {
        printf("open error!");
        return -1;
    }

    //读写
    if (0 == strcmp(argv[1], "-w") && argc == 3)
    {
        //写
        len = strlen(argv[2]);
        len = (len < 1024) ? len : 1024;
        write(fd, argv[2], len);
    }
    else {
        //读
        len = read(fd, buf, 4);
        buf[len] = '\0';
        printf("read:%s\n", buf);
    }

    close(fd);

    return 0;
}